﻿using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace eLoan.Models
{
    [Table("Loan")]
    public class Loan: LoanFields
    { }

    public class LoanModel
    {
        public Loan Loan { get; set; }

        [Display(Name = "Branch")]
        public string BranchName { get; set; }

        [Display(Name = "Borrower")]
        public string BorrowerName { get; set; }

        [Display(Name = "Agent")]
        public string AgentName { get; set; }

        [Display(Name = "Proceed Type")]
        public string ProceedTypeName { get; set; }

        [Display(Name = "Loan Type")]
        public string LoanTypeName { get; set; }

        [Display(Name = "Payment Type")]
        public string PaymentTypeName { get; set; }

        [Display(Name = "Loan Interest Amount")]
        public decimal LoanInterestAmount { get; set; }

        [Display(Name = "Loan Status")]
        public string LoanStatus { get; set; }

    }

    public class LoanQueryModel: LoanFields
    {
        [Display(Name = "Branch")]
        public string BranchName { get; set; }

        [Display(Name = "Borrower")]
        public string BorrowerName { get; set; }

        [Display(Name = "Agent")]
        public string AgentName { get; set; }

        [Display(Name = "Payment Frequency")]
        public string ProceedTypeName { get; set; }

        [Display(Name = "Loan Type")]
        public string LoanTypeName { get; set; }

        [Display(Name = "Payment Type")]
        public string PaymentTypeName { get; set; }

        [Display(Name = "Loan Interest Amount")]
        public decimal LoanInterestAmount { get; set; }

        [Display(Name = "Receivable")]
        public decimal Receivable { get; set; }

        [Display(Name = "Due To Date")]
        public decimal DueToDate { get; set; }

        [Display(Name = "Total Deduction")]
        public decimal TotalDeduction { get; set; }

        [Display(Name = "Cheque Amount")]
        public decimal ChequeAmount { get; set; }

        [Display(Name = "Total Penalty")]
        public decimal TotalPenalty { get; set; }

        [Display(Name = "Total Payment")]
        public decimal TotalPayment { get; set; }

        [Display(Name = "Outstanding Balance")]
        public decimal OutstandingBalance { get; set; }

        [Display(Name = "Loan Status")]
        public string LoanStatus { get; set; }
    }

    public class LoanFields
    {
        [Key]
        [Display(Name = "Document No")]
        public string DocumentNo { get; set; }

        [Required]
        [Display(Name = "Document Date")]
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
        public DateTime DocumentDate { get; set; }

        [Required]
        [Display(Name = "Branch")]
        public string BranchCode { get; set; }

        [Required]
        [Display(Name = "Borrower")]
        public int BorrowerID { get; set; }

        [Required]
        [Display(Name = "Agent")]
        public int AgentID { get; set; }

        [Required]
        [Display(Name = "Proceed Type")]
        public int ProceedTypeID { get; set; }

        [Required]
        [Display(Name = "Loan Type")]
        public int LoanTypeID { get; set; }

        [Required]
        [Display(Name = "Payment Type")]
        public int PaymentTypeID { get; set; }

        [Required]
        [Display(Name = "Term")]
        public int Term { get; set; }

        [Required]
        [Display(Name = "Credit Limit")]
        public decimal CreditLimit { get; set; }

        [Required]
        [Display(Name = "Loan Amount")]
        public decimal LoanAmount { get; set; }

        [Required]
        [Display(Name = "Loan Interest %")]
        [Range(1, 100)]
        public decimal LoanInterest { get; set; }

        [Display(Name = "Payment Start Date")]
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
        public DateTime? PaymentStartDate { get; set; }

        [Display(Name = "Payment End Date")]
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
        public DateTime? PaymentEndDate { get; set; }

        [Display(Name = "2nd Date (Day of the same month)")]
        [Range(0, 31)]
        public int PaymentSecondDate { get; set; }

        [Required]
        [Display(Name = "Encoded By")]
        [StringLength(56)]
        public string EncodedBy { get; set; }

        [Required]
        [Display(Name = "Loan Status")]
        public int StatusID { get; set; }

        [Display(Name = "Is Active")]
        public bool IsActive { get; set; }

        [Display(Name = "Remarks")]
        public int? RemarkID { get; set; }

        public DateTime? DateClosed { get; set; }

        public DateTime? DateReleased { get; set; }
    }
}